package com.deYang.app.ljodfh.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.deYang.app.ljodfh.R;
import com.deYang.app.ljodfh.beans.FComment;
import com.deYang.app.ljodfh.ui.utils.GlideCircleTransform;
import com.deYang.app.ljodfh.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liuyu on 2017/8/22.
 */

public class CLCommentHolder extends BaseRecylerHolder<FComment> implements View.OnClickListener {
    @BindView(R.id.item_comment_icon)
    protected ImageView icon;
    @BindView(R.id.item_comment_name)
    protected CustomFontTextView name;
    @BindView(R.id.item_comment_reply)
    protected CustomFontTextView replay;
    @BindView(R.id.item_comment_time)
    protected CustomFontTextView time;
    @BindView(R.id.item_comment_content)
    protected CustomFontTextView content;

    private FComment fComment;

    public CLCommentHolder(final Context context, View itemView) {
        super(context, itemView);
        replay.setOnClickListener(this);
//        content.setOnStateChangeSetting(new TextViewExpandableAnimation.OnStateChangeSetting() {
//            @Override
//            public void reInitStateView(TextView stateView) {
////                stateView.setBackgroundResource(R.drawable.bg_comment_all_l);
//                stateView.setText(R.string.newes_see_all);
////                ViewGroup.MarginLayoutParams mlp= (ViewGroup.MarginLayoutParams) stateView.getLayoutParams();
////                mlp.topMargin= DensityUtil.dip2px(context,18);
////                stateView.setLayoutParams(mlp);
//            }
//
//            @Override
//            public void onStateChanged(TextView stateView, boolean isShrink) {
//                JLog.e(" is shrink=" + isShrink + "   " + this);
//                content.getStateImg().setRotation(isShrink ? 90 : -90);
//            }
//        });
//
//        content.setOnStateChangeListener(new TextViewExpandableAnimation.OnStateChangeListener() {
//            @Override
//            public void onStateChange(boolean isShrink) {
//                if (fComment != null) {
//                    fComment.setShrink(isShrink);
//                }
//            }
//        });
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FComment fComment) {
        replay.setTag(R.id.adapter_item_data_key, fComment);
        if (TextUtils.isEmpty(fComment.getAnswerTo())) {
            name.setText(fComment.getNickName());
            replay.setVisibility(View.VISIBLE);
        } else {
            name.setText(fComment.getNameSpanned());
            replay.setVisibility(View.GONE);
        }
        time.setText(DateUtils.timeAgo(DateUtils.getDataDate(fComment)));
        content.setText(fComment.getComment());

//        content.resetState(fComment.isShrink());
        GlideUtil.getGlideWithAvatorDef(context, fComment.getAvatar()).error(R.mipmap.icon_circle_avatar)
                .placeholder(R.mipmap.icon_circle_avatar).transform(new GlideCircleTransform(context)).into(icon);
//        if (!TextUtils.isEmpty(fComment.getAvatar())) {
//        }
    }

    @Override
    public void onClick(View v) {
        JLog.e("replay click internal is " + internalClick);
        if (internalClick != null) {
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }

}
